import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../../res/HDColors.dart';
import '../../../../view/FieldEditor.dart';
import '../../../../view/FieldFile.dart';
import '../../../../view/common_widget.dart';
import '../../../../view/image_picker_widget.dart';
import 'logic.dart';

class StartApprovalPage extends StatelessWidget {
  StartApprovalPage({Key? key}) : super(key: key);

  final logic = Get.put(StartApprovalPageLogic());
  final state = Get.find<StartApprovalPageLogic>().state;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<StartApprovalPageLogic>(builder: (logic) {
      return pageWidget();
    });
  }

  pageWidget() {
    return SingleChildScrollView(
      child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        FieldEditor(
            label: '备注',
            hintText: '请输入备注信息',
            initialValue: state.startedApproval.remarks,
            contentTextAlign: TextAlign.end,
            showLine: false,
            isRequired: false,
            readOnly: state.isReadOnly,
            controller: state.rnRemarkController
              ..text = state.startedApproval.remarks ?? "",
            onChanged: (value) {
              state.startedApproval.remarks = value;
            }),
        Visibility(
          visible: !state.isReadOnly,
          child: FieldFile(
            listData: [],
            filePickerController: state.contractFileController,
            label: "合同",
            readOnly: false,
            isRequired: false,
            initialValue: state.contractFileController.getFiles(),
          ),
        ),
        Visibility(
          visible: !state.isReadOnly,
          child: FieldFile(
            listData: [],
            filePickerController: state.propertyFileController,
            label: "房产证明",
            readOnly: false,
            isRequired: false,
            initialValue:state.propertyFileController.getFiles(),
          ),
        ),
        Visibility(
          visible: !state.isReadOnly,
          child: FieldFile(
            listData: [],
            filePickerController: state.copyIdFileController,
            label: "身份证复印件",
            readOnly: false,
            isRequired: false,
            initialValue: state.copyIdFileController.getFiles(),
          ),
        ),
        Visibility(
          visible: !state.isReadOnly,
          child: FieldFile(
            listData: [],
            filePickerController: state.reportFileController,
            label: "开工报审表",
            readOnly: false,
            initialValue: state.reportFileController.getFiles(),
          ),
        ),
        Visibility(
          visible: !state.isReadOnly,
          child: FieldFile(
            listData: [],
            filePickerController: state.constructionFileController,
            label: "接入条件+施工方案",
            readOnly: false,
            isRequired: false,
            initialValue:state.constructionFileController.getFiles(),
          ),
        ),
        Visibility(
          visible: !state.isReadOnly,
          child: FieldFile(
            listData: [],
            filePickerController: state.designPhotoFileController,
            label: "设计图",
            readOnly: false,
            isRequired: false,
            initialValue: state.designPhotoFileController.getFiles(),
          ),
        ),
        Visibility(
          visible: !state.isReadOnly,
          child: FieldFile(
            listData: [],
            filePickerController: state.loadReportFileController,
            label: "荷载报告",
            readOnly: false,
            isRequired: false,
            initialValue: state.loadReportFileController.getFiles(),
          ),
        ),
        Visibility(
            visible: state.isReadOnly,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 20, 20, 0),
                  child: Text('合同',
                      style: TextStyle(color: HDColors.black, fontSize: 16)),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                  child: ImagePickerWidget(
                    controller: state.contractController,
                    readonly: state.isReadOnly,
                  ),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 20, 20, 0),
                  child: Text('房产证明',
                      style: TextStyle(color: HDColors.black, fontSize: 16)),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                  child: ImagePickerWidget(
                    controller: state.propertyCertificateController,
                    readonly: state.isReadOnly,
                  ),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 20, 20, 0),
                  child: Text('身份证复印件',
                      style: TextStyle(color: HDColors.black, fontSize: 16)),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                  child: ImagePickerWidget(
                    controller: state.copyIdCardController,
                    readonly: state.isReadOnly,
                  ),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 20, 20, 0),
                  child: Text('开工报审表',
                      style: TextStyle(color: HDColors.black, fontSize: 16)),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                  child: ImagePickerWidget(
                    controller: state.reportController,
                    readonly: state.isReadOnly,
                  ),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 20, 20, 0),
                  child: Text('接入条件+施工方案',
                      style: TextStyle(color: HDColors.black, fontSize: 16)),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                  child: ImagePickerWidget(
                    controller: state.constructionController,
                    readonly: state.isReadOnly,
                  ),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 20, 20, 0),
                  child: Text('设计图',
                      style: TextStyle(color: HDColors.black, fontSize: 16)),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                  child: ImagePickerWidget(
                    controller: state.designPhotoController,
                    readonly: state.isReadOnly,
                  ),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 20, 20, 0),
                  child: Text('荷载报告',
                      style: TextStyle(color: HDColors.black, fontSize: 16)),
                ),
                Container(
                  margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
                  child: ImagePickerWidget(
                    controller: state.loadReportController,
                    readonly: state.isReadOnly,
                  ),
                )
              ],
            )),
        Container(
          margin: const EdgeInsets.fromLTRB(13, 20, 20, 0),
          child:
              Text('其他', style: TextStyle(color: HDColors.black, fontSize: 16)),
        ),
        Container(
          margin: const EdgeInsets.fromLTRB(13, 10, 20, 0),
          child: ImagePickerWidget(
            controller: state.otherController,
            readonly: state.isReadOnly,
          ),
        ),
        Visibility(visible: !state.isReadOnly, child: getFooterButton())
      ]),
    );
  }

  getFooterButton() {
    return Container(
        decoration: const BoxDecoration(color: HDColors.white, boxShadow: [
          BoxShadow(
              color: HDColors.grayBg,
              offset: Offset(0, -2),
              blurRadius: 8,
              spreadRadius: 1)
        ]),
        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 10),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            CommonWidget.buildBottomBtn("暂存", () {
              logic.save();
            }),
            CommonWidget.buildBottomBtn("提交", () {
              logic.submit(1);
            }),
          ],
        ));
  }
}
